package com.loongtech.bi.action.biflow;

import com.loongtech.bi.advertisment.controller.BaseAdvAction;
import com.loongtech.bi.cs.model.AddcashEntity;
import com.loongtech.bi.cs.service.impl.AddcashServiceImpl;
import com.loongtech.bi.manager.system.BiPlatformManager;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Scope("prototype")
@RequestMapping("/flow/addcashFlow")
public class AddcashController extends BaseAdvAction {

	private static final long serialVersionUID = 1L;

	@Resource(name = "addcashServiceImpl")
	private AddcashServiceImpl service;

	@RequestMapping(value = "search.do", method = { RequestMethod.GET, RequestMethod.POST })
	public void search(HttpServletRequest request, HttpServletResponse response, @RequestParam String day,
			@RequestParam String userid, @RequestParam String roleid, String callback) {
		try {
			Map<String, Object> result = new HashMap<String, Object>();

			if ((("".equals(userid) || userid.length() <= 0)) && (("".equals(roleid) || roleid.length() <= 0))) {
				result.put("res", "1");
				result.put("msg", "用户或角色id必须至少输入一个!");
				printToJson(response, result, callback);
				return;
			}
			List<AddcashEntity> ret = service.getAddcash(day, userid, roleid);
			for (AddcashEntity addcash : ret) {
				addcash.setChannelid(BiPlatformManager.getChannelNameById(addcash.getChannelid()));
				addcash.setServerid(BiPlatformManager.getServerNameById(addcash.getServerid()));
				addcash.setPlatform(BiPlatformManager.getPlatformNameById(addcash.getPlatform()));
			}
			result.put("res", "0");
			result.put("retlist", ret);
			printToJson(response, result, callback);
		} catch (Exception e) {
			e.printStackTrace();
			Map<String, Object> result = new HashMap<String, Object>();
			result.put("res", "1");
			result.put("msg", e.getMessage());
			printToJson(response, result, callback);
			return;
		}
	}
}
